package thitracnghiem;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.Properties;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
/**
 *
 * @author Odotube
 */
public class CauTraLoi {

    String maCauHoi;
    String maLuaChon;
    String luaChon;
    static Connection conn;
    static Statement stm;

    public CauTraLoi(String maCauHoi, String maLC, String luaChon) {
        this.maCauHoi = maCauHoi;
        this.maLuaChon = maLC;
        this.luaChon = luaChon;
    }

    public static void Open() throws SQLException {
        conn = DriverManager.getConnection("jdbc:odbc:ttn");
        stm = conn.createStatement();
    }

    public static void Close() throws SQLException {
        stm.close();
        conn.close();
    }

    public static void delCauTraLoi(String maCauHoi) throws SQLException {
        String sql = "delete CauTraLoi where macauhoi='" + maCauHoi + "'";
        stm.executeUpdate(sql);
    }

    public void insCauTraLoi() throws SQLException {
        String sql = "insert into CauTraLoi values('" + maCauHoi + "','" + maLuaChon + "',N'" + luaChon + "')";
        Open();
        stm.executeUpdate(sql);
        Close();
    }

    public String getLuaChon() {
        return this.luaChon;
    }

    public void setMaCauHoi(String maCauHoi) {
        this.maCauHoi = maCauHoi;
    }

    public static ArrayList<CauTraLoi> getDSCauTraLoi(String maCauHoi) throws SQLException {
        ArrayList<CauTraLoi> mList = new ArrayList<CauTraLoi>();
        String sql = "select * from CauTraLoi where macauhoi='" + maCauHoi + "'";
        Open();
        ResultSet rs = stm.executeQuery(sql);
        while (rs.next()) {
            mList.add(new CauTraLoi(rs.getString(1), rs.getString(2), rs.getString(3)));
        }
        Close();
        return mList;
    }

    public String getMaLuaChon() {
        return maLuaChon;
    }

    public void setMaLuaChon(String maLuaChon) {
        this.maLuaChon = maLuaChon;
    }
}
